function initEditPanel(json) {
	createPageButton(json);
	//加载字段信息
	$.post(host + "showAction/getModuleFieldList.html", {"moduleId": json.id}, function(data) {
		pageParam.fields[json.code] = data.list;
		createEditPanel(json, data.list);
		initPageData(json, data.list);
	}, "json");
}
function initPageData(json, array) {
	var type = baseJs.request("type");
	if (type == "modify") {
		var data = baseJs.request();
		var params = {};
		params["code"] = data["code"];
		var ids = data["edit_ids"].split(",");
		
		for (var i = 0;i < ids.length;i ++) {
			params[ids[i]] = data[ids[i]];
		}
		
		$.post(host + "showAction/getModuleData.html", params, function(data) {
			if (data.status == "error") {
				alert(data.msg);
			} else{
				initEditData(json.code, data);
			}
		}, "json");
	}
}
function initEditData(code, data) {
	pageParam.data[code] = data;
	var array = pageParam.fields[code];
	try {
		for (var i = 0;i < array.length;i ++) {
			var value = data[getAliasName(array[i].tableName + "_" + array[i].fieldName)];
			if (value == undefined) {
				value = "";
			}
			if (array[i].type == "date" || array[i].format == "yyyy-MM-dd") {
				$("#" + array[i].tableName + "_" + array[i].fieldName).datebox({value: value});
			} else {
				$("#" + array[i].tableName + "_" + array[i].fieldName).val(value);
			}
		}
	} catch (e) {
		alert("CODE:" + code);
	}
}
function createPageButton(json) {
	//显示按钮
	var btns = [];
	var buttons = {};
	eval("buttons=" + json.buttons);
	for (var btn in buttons) {
		btns.push(buttons[btn]);
	}
	if (btns.length > 0) {
		pageParam.buttons[json.code] = buttons;
		var layout = createLayout(json);
		var table = $('<div class="page-toolbar-right"></div>');
		var toolbar = $('<div class="page-toolbar"></div>');
		layout.append(toolbar);
		toolbar.append(table);
		for (var btn in buttons) {
			if (buttons[btn].checked != "false") {
				var button = $('<a class="easyui-linkbutton" icon="' + buttons[btn].iconCls + 
					'" href="javascript:void(0)" onclick="buttonEvent(\'' + json.code + '\', \'' + btn + '\');return false;">' + 
					buttons[btn].text + '</a>');
				table.append(button);
				table.append($("<span stlye=''>&nbsp;</span>"));
			}
		}
	}
}
function createEditPanel(json, array) {
	var html = ['<table class="edit_table"><tr>'];
	var input = [];
	var table = $('<div class="layout-edit-table"></div>');
	var layout = createLayout(json);
	layout.append(table);
	var colIndex = 0;
	for (var i = 0;i < array.length;i ++) {
		var data = array[i];
		if ((colIndex != 0 || data.newLine == 'Y') && colIndex % json.pageSize == 0) {
			html.push("</tr><tr>");
			colIndex = 0;
		}
		if (data.isHide == 1) {
			//如果是隐藏，并且有默认值，则数据在后台处理
			if (data.isId == 1 || data.defaultValue == undefined || data.defaultValue == "") {
				//table.append($('<input type="hidden" id="' + data.tableName + "_" + data.fieldName + '"/>'));
				input.push('<input type="hidden" id="' + data.tableName + "_" + data.fieldName + '"/>');
			}
		} else {
			var disabled = "";
			if (data.isNotUpdate == 'Y') {
				disabled = "disabled='disabled'";
			}
			/*
				<option value="text">字符串</option>
				<option value="number">数字</option>
				<option value="select">下拉框</option>
				<option value="textarea">文本</option>
				<option value="date">时间</option>
				<option value="tree">树形结构</option>
				<option value="open">弹出选择窗口</option>
			*/
			html.push("<th>" + data.name + "：</th>");
			if (data.colSpan && data.colSpan > 1) {
				html.push("<td colSpan='" + (data.colSpan * 2 - 1) + "'>");
				colIndex += data.colSpan;
			} else {
				colIndex ++;
				html.push("<td>");
			}
			//var html = ['<div class="layout-edit-cell">',
			//			'<div class="layout-edit-title">', data.name, '：</div>'];
			var width = 150;
			if (data.width > 150) {
				width = data.width * 1;
			}
			if (data.type == "select") {
				//html.push('<div class="layout-edit-input" style="width: ' + (width + 20) + 'px">');
				html.push('<select id="' + data.tableName + "_" + data.fieldName + '" ');
				html.push(disabled);
				html.push(' style="width: ' + width + 'px;">');
				if (data.options) {
					html.push("<option value=''>--请选择--</option>");
					var options = {};
					eval("options = " + data.options);
					var valueField = options.valueField ? options.valueField : "value";
					var textField = options.textField ? options.textField : "text";
					for (var j = 0;j < options.data.length;j ++) {
						html.push("<option value='" + options.data[j][valueField] + "'>" + options.data[j][textField] + "</option>");
					}
				}
				html.push('</select>');
			} else if (data.type == "textarea") {
				//html.push('<div class="layout-edit-input" style="width: ' + (width + 20) + 'px">');
				html.push('<textarea id="' + data.tableName + "_" + data.fieldName + '" ');
				html.push(disabled);
				html.push(' style="height: ' + (data.height > 10 ? data.height : 40) + 'px;width: ' + width + 'px;">');
				html.push('</textarea>');
			} else if (data.type == "date" || data.format == "yyyy-MM-dd") {
				//html.push('<div class="layout-edit-input" style="width: ' + (width + 20) + 'px">');
				html.push('<input id="' + data.tableName + "_" + data.fieldName + '" class="easyui-datebox" ');
				html.push(disabled);
				html.push(' style="width: ' + width + 'px;"/>');
				//html.push('</div>');
			} else if (data.type == "text" || data.type == "number") {
				//html.push('<div class="layout-edit-input" style="width: ' + (width + 20) + 'px">');
				html.push('<input id="' + data.tableName + "_" + data.fieldName + '" ');
				html.push(disabled);
				html.push(' style="width: ' + width + 'px;"/>');
				//html.push('</div>');
			}
			html.push('</td>');
			if (data.type == "date" || data.format == "yyyy-MM-dd") {
				if (data.defaultValue) {
					$("#" + data.tableName + "_" + data.fieldName).datebox({value: data.defaultValue});
				} else {
					$("#" + data.tableName + "_" + data.fieldName).datebox({});
				}
			} else if (data.defaultValue != undefined && data.defaultValue != "") {
				$("#" + data.tableName + "_" + data.fieldName).val(data.defaultValue);
			}
		}
		html.push(input.join(""));
		table.html(html.join(""));
	}
}